/**
 * Created by wyy on 17-7-30.
 */
angular.module('tribalc').controller('rentPaymentController',
    ['$scope','$rootScope','Api','Alert','$state','$stateParams',function ($scope,$rootScope,Api,Alert,$state,$stateParams) {
        $scope.apartmentId = $stateParams.apartmentId;

        getRentpaymentInfo();
        function getRentpaymentInfo() {
            var sourceId=$stateParams.apartmentId;
            Api.getRentlistInfo(sourceId,function (result) {
                if(result.data !== null){
                    Api.getRentpaymentInfo(result.data.id,function(result) {
                        $scope.paymentinfolist = result.data;
                        getTime(result.data);
                    });
                }

            });
        }


        $scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {
            if ($scope.paymentinfolist) {
                $('.MARGIN:odd').addClass('margin-right')
            }
        });

        function getTime(result) {
            var curentdate;
            curentdate= Date.parse(new Date());
            for (var i =0;i<result.length;i++) {
                var payStatus = '未还款';
                var payStatusColor = "";
                if (curentdate < result[i].plannedTime && result[i].finished == false && result[i].actualPay > 0) {
                    payStatus = '还款中';
                    payStatusColor = 'paying';
                }
                if (curentdate < result[i].plannedTime && result[i].finished == false && result[i].actualPay == 0) {
                    payStatus = '未还款';
                    payStatusColor = '';
                }

                if (curentdate > result[i].plannedTime && result[i].finished == false && result[i].actualPay == 0) {
                    payStatus = '逾期';
                    payStatusColor = 'over-pay';
                }
                if (curentdate > result[i].plannedTime && result[i].finished == true && result[i].actualPay > 0) {
                    payStatus = '已还款';
                    payStatusColor = 'payed';
                }
                result[i].payStatus=payStatus;
                result[i].payStatusColor=payStatusColor;
            }

        }


    }]);

